package com.ghy.controller;

import com.ghy.dto.CouponsInsertDTO;
import com.ghy.dto.CouponsPageDTO;
import com.ghy.dto.CouponsUpdateDTO;
import com.ghy.entity.Coupons;
import com.ghy.vo.CouponsSimpleListVO;
import com.mybatisflex.core.paginate.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.ghy.service.CouponsService;

import java.util.List;

/**
 * 优惠卷表 控制层。
 *
 * @author ghy
 * @since 2024-12-22
 */
@Tag(name = "优惠卷")
@RestController
@RequestMapping("/coupons")
public class CouponsController {

    @Autowired
    private CouponsService couponsService;

    @Operation(summary ="新增——单条",description ="新增一条优惠卷记录")
    @PostMapping("insert")
    public boolean insert(@Validated @RequestBody CouponsInsertDTO dto) {
        return couponsService.insert(dto);
    }

    @Operation(summary ="查询——前n条",description ="按主键查询一条优惠卷记录")
    @GetMapping("top/{n}")
    public List<Coupons> top (@PathVariable Long n) {
        return couponsService.top(n);
    }

    @Operation(summary ="查询——单条",description ="按主键查询一条优惠卷记录")
    @GetMapping("select/{id}")
    public Coupons select(@PathVariable("id") Long id) {
        return couponsService.select(id);
    }

    @Operation(summary = "查询——简单查询全部", description = "查询全部优惠卷记录")

    @GetMapping("simpleList")
    public List<CouponsSimpleListVO> simpleList() {
        return couponsService.simpleList();
    }


    @Operation(summary ="查询——分页",description ="分页查询优惠卷记录")
    @GetMapping("page")
    public Page<Coupons> page(@Validated CouponsPageDTO dto) {
        return couponsService.page(dto);
    }

    @Operation(summary="修改——单条",description="按主键修改一条优惠卷记录")
    @PutMapping("update")
    public boolean update(@RequestBody CouponsUpdateDTO dto) {
        return couponsService.update(dto);
    }

    @Operation(summary ="删除——单条",description ="按主键删除一条优惠卷记录")
    @DeleteMapping("delete/{id}")
    public boolean delete(@PathVariable("id") Long id) {
        return couponsService.delete(id);
    }

    @Operation(summary="删除——批量",description ="按主键批量删除优惠卷记录")
    @DeleteMapping("deleteBatch")
    public boolean deleteBatch(@RequestParam("ids") List<Long> ids) {
        return couponsService.deleteBatch(ids);
    }

    @Operation(summary = "查询 - 兑换口令", description = "按兑换口令查询一条优惠卷记录")
    @GetMapping("selectByCode/{code}")
    public Coupons selectByCode(@PathVariable("code") String code) {
        return couponsService.selectByCode(code);
    }

}
